package vek.Objects;

import vek.XML.parsedObjects.ParsedAddresse;

/**
 * Adresse which contains a road, roadnumber, postcode, city and country
 * This class is used by the POIs as each POI as an addresse.
 * @author Christian, Michal og Jakob (Hold 1, gruppe 2)
 */
public class Addresse {
    
    private String road;
    private int roadNumber;
    private String extrainfo;
    private int postcode;
    private String city;
    private String country;
    
    /**
     * Creates an Addresse object and assigns its varaibles using data from the a ParsedObject.
     * @param pa the ParsedAddresse which contains all the variables for this object
     */
    
    public Addresse(ParsedAddresse pa)
    {
        road = pa.road;
        roadNumber = pa.roadNumber;
        extrainfo = pa.extrainfo;
        postcode = pa.postcode;
        city = pa.city;
        country = pa.country;
    }
    
    /**
     * Gets the object as a string
     * @return this object as a string
     */
    
    public String toString()
    {
        return road + " " + roadNumber + " " + extrainfo + postcode + ", "
                + city + ", " + country;
    }
    
    /**
     * Gets this addresse with just the road, roadnumber and extra info
     * @return the addresse as a string, but only the road, roadnumber and extra info
     */
    
    public String getShortAdresse()
    {
        if(extrainfo.equals("") || extrainfo == null)
        {
            return road + " " + roadNumber;
        }
        else
        {
            return road + " " + roadNumber + " " + extrainfo;
        }
    }
    
    /**
     * Gets the road
     * @return the variable road which contains the road of this addresse
     */
    
    public String getRoad()
    {
        return road;
    }
    
    /**
     * Gets the roadnumber
     * @return the roadnumber
     */
    
    public int getRoadNumber()
    {
        return roadNumber;
    }
    
    /**
     * Gets the extra info, this can be floor number similiar.
     * @return the extrainfo variable which MAY contain extra info, might be blank
     */
    public String getExtraInfo()
    {
        return extrainfo;
    }
    
    /**
     * Gets the postcode of this addresse
     * @return the postcode of this addresse
     */
    public int getPostCode()
    {
        return postcode;
    }
    
    /**
     * Gets the city of this addresse
     * @return the city of this addresse
     */
    
    public String getCity()
    {
        return city;
    }
    
    /**
     * Gets the country of this addresse
     * @return the country of this addresse
     */
    
    public String getCountry()
    {
        return country;
    }
    
    /**
     * Checks if the road starts with the specified string.
     * 
     * NOTE: this method is NOT case sensitive
     * 
     * @param s the string which the road should start with to return true
     * @return true if the road starts with the specified string
     */
    
    public boolean roadStartsWith(String s)
    {
        if(road.toLowerCase().startsWith(s.toLowerCase()))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    /**
     * Compares to addresses.
     * To addresses are the same if all the variables are the same.
     * This overrides the equals method in object, which is based on memory.
     * 
     * NOTE: Cast exception can occur if the given object is not an Addresse, avoid this
     * 
     * @param o the Addresse to compare this object to
     * @return true if the variables in the compared addresse are the same as the variables in this addresse
     */
    
    public boolean equals(Object o)
    {
        if(o == null)
        {
            return false;
        }
        Addresse a = (Addresse) o;
        if( a.getRoad().equals(this.getRoad()) && a.getRoadNumber() == this.getRoadNumber()
                && a.getExtraInfo().equals(this.getExtraInfo()) 
                && a.getPostCode() == this.getPostCode() && a.getCity().equals(this.getCity())
                && a.getCountry().equals(this.getCountry()))
        {
            return true;
        }
        else
        {
            return false;
        }
    }


}
